
#include "SceneManager.h"
#include "WelcomeScene.h"
#include "GameScene.h"

SceneManager * SceneManager::m_pSceneManager=NULL;

SceneManager::SceneManager()
{

}

SceneManager::~SceneManager()
{

}

void SceneManager::changeScene( EnumSceneType enScenType ) 
{
	changeScene(enScenType, false);
}

void SceneManager::changeScene( EnumSceneType enScenType, bool isTrans ) 
{
	changeScene(enScenType, isTrans, 1.0f);
}

void SceneManager::changeScene( EnumSceneType enScenType, bool isTrans, float time ) 
{
	CCScene* pScene = getSceneByType(enScenType);

	if(pScene == NULL) 
	{
		return;
	}
	CCTextureCache::sharedTextureCache()->removeUnusedTextures();
	CCDirector* pDirector = CCDirector::sharedDirector();
	CCScene* curScene = pDirector->getRunningScene();
	if(curScene == NULL) 
	{
		pDirector->runWithScene(pScene);
	}
	else 
	{
		if(isTrans) 
		{
			pDirector->replaceScene(CCTransitionFade::create(time, pScene));
		}
		else 
		{
			pDirector->replaceScene(pScene);
		}
	}
}

CCScene * SceneManager::getSceneByType(EnumSceneType enSceneType)
{
	CCScene * t_pScene=NULL;

	switch(enSceneType)
	{
	case en_WelcomeScene:
		t_pScene=WelcomeScene::create();
		break;
	case en_GameScene:
		t_pScene=GameScene::create();
		break;
	default:
		break;
	}

	return t_pScene;
}